﻿package mortal.game.view.rebate.dayRecharge
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.item.*;
    import mortal.game.view.signUp.sevenDayLogin.data.*;
    import mortal.mvc.core.*;

    public class RebateDayRechargeCell2 extends GCellRenderer
    {
        protected var _items:CellsGridSprite;
        protected var _title:GBitmap;
        protected var _getBtn:GLoadingButton;
        protected var _hasGetFlag:GImageBitmap;
        protected var _timesDes:GTextFiled;
        protected var _timeTxt:GTextFiled;
        private var _info:Object;
        private static var _posArr:Array = [421, 470, 503, 542, 585, 625, 667];

        public function RebateDayRechargeCell2()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._items = UIFactory.getUICompoment(CellsGridSprite);
            this._items.colNum = 10;
            this._items.vCellWid = 45;
            this._items.hCellWid = 100;
            this._items.genCellFun = this.genItem;
            this._items.genCells(4);
            this._items.x = 221;
            this._items.y = 1;
            this.addChild(this._items);
            this._title = UIFactory.gBitmap(ImagesConst.RebateDayRechargeLT6, 0, 6, this);
            this._getBtn = UIFactory.gLoadingButton(ImagesConst.RebateListGetBtn2_upSkin, 421, -2, 99, 43, this);
            this._getBtn.label = "";
            this._hasGetFlag = UIFactory.gImageBitmap(ImagesConst.HasGetRewardFlag, 445, 2, this);
            this._timesDes = UIFactory.gTextField(Language.getString(35527), 33, 25, 100, 20, this, GlobalStyle.textFormatLv);
            this._timeTxt = UIFactory.gTextField("10/10", 104, 25, 100, 20, this, GlobalStyle.textFormatLv);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onCkHd);
            return;
        }// end function

        private function genItem() : RebateItem2
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateItem2);
            return _loc_1;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.setBtn(true);
            SevenDayLoginUtil.showGuideArrow(this._getBtn, false, this);
            this._items = null;
            this._title = null;
            this._getBtn = null;
            this._hasGetFlag = null;
            this._timesDes = null;
            this._timeTxt = null;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._info = param1;
            if (this._info == null)
            {
                return;
            }
            this.updateTitle();
            this.updateGiftBag();
            this.updateBtn();
            return;
        }// end function

        private function updateTitle() : void
        {
            var _loc_1:* = this._info.index;
            this._title.bitmapData = GlobalClass.getBitmapData(ImagesConst["RebateDayRechargeLT" + (_loc_1 + 1)]);
            return;
        }// end function

        private function updateGiftBag() : void
        {
            var _loc_6:SPlayerItem = null;
            var _loc_7:RebateItem2 = null;
            var _loc_1:* = this._info.giftBag;
            var _loc_2:* = ItemConfig.instance.getConfig(_loc_1);
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = (_loc_2 as ItemGiftBagInfo).itemList;
            var _loc_4:* = QuestionCopyConfig.instance().getRewardItems(_loc_3);
            if (_loc_4 == null || _loc_4.length == 0)
            {
                return;
            }
            this._items.genCells(_loc_4.length);
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4.length)
            {
                
                _loc_6 = _loc_4[_loc_5];
                _loc_7 = this._items.cellArr[_loc_5];
                _loc_7.updateInfo(_loc_6);
                _loc_5++;
            }
            return;
        }// end function

        public function updateBtn() : void
        {
            var _loc_1:* = RebateUtil.getRwState(this._info.index);
            var _loc_2:* = this._info.returnTimes;
            var _loc_3:* = _loc_1[1];
            this._timeTxt.text = _loc_3 + "/" + _loc_2;
            var _loc_4:* = this._info.index;
            this._getBtn.x = _posArr[_loc_4];
            this._hasGetFlag.x = this._getBtn.x + 25;
            if (Cache.instance.rebate.dayRechargeInfo == null)
            {
                this.setBtn(false);
                return;
            }
            switch(_loc_1[0])
            {
                case 0:
                {
                    this.setBtn(false);
                    this._hasGetFlag.visible = true;
                    break;
                }
                case 1:
                {
                    this.setBtn(true);
                    this._hasGetFlag.visible = false;
                    break;
                }
                case 2:
                {
                    this.setBtn(false);
                    this._hasGetFlag.visible = _loc_3 > 0;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function canGetReward() : Boolean
        {
            var _loc_1:* = RebateUtil.dayRechargeArr[this._info.index];
            if (Cache.instance.rebate.dayRechargeInfo == null)
            {
                return false;
            }
            var _loc_2:* = RebateUtil.getRwState(this._info.index);
            return _loc_2[0] == 1;
        }// end function

        private function setBtn(param1:Boolean) : void
        {
            if (param1)
            {
                this._getBtn.enabled = true;
                this._getBtn.filters = null;
                SevenDayLoginUtil.showGuideArrow(this._getBtn, true, this);
            }
            else
            {
                SevenDayLoginUtil.showGuideArrow(this._getBtn, false, this);
                this._getBtn.enabled = false;
                this._getBtn.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        private function onCkHd(event:MouseEvent) : void
        {
            var _loc_2:* = RebateUtil.dayRechargeArr[this._info.index];
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateDayRechargeGetReward, _loc_2));
            return;
        }// end function

        public function flyIcon(param1:int) : void
        {
            var _loc_3:int = 0;
            var _loc_4:RebateItem2 = null;
            var _loc_2:* = RebateUtil.dayRechargeArr[this._info.index];
            if (param1 == _loc_2 && this._items)
            {
                _loc_3 = 0;
                while (_loc_3 < this._items.cellArr.length)
                {
                    
                    _loc_4 = this._items.cellArr[_loc_3];
                    _loc_4.flyIcon();
                    _loc_3++;
                }
            }
            return;
        }// end function

    }
}
